package cn.stylefeng.guns.weixin.common;

import cn.ucloud.common.pojo.Account;
import cn.ucloud.usms.client.DefaultUSMSClient;
import cn.ucloud.usms.client.USMSClient;
import cn.ucloud.usms.model.SendUSMSMessageParam;
import cn.ucloud.usms.model.SendUSMSMessageResult;
import cn.ucloud.usms.pojo.USMSConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * ucloud 短信 公共类
 */

public class SendSmsUtils2 {

    //SMS方法中有两个参数，这个参数是由前台页面提交的PostData和前者绑定的短信服务地址确定的
    public static String SMS(String phoneNumber,String code) {
        USMSClient client = new DefaultUSMSClient(new USMSConfig(
                new Account(
                        "FN3nfCZLpdnKURCWRmTbNP1xcvKOcx4qJBQlwa9hl2dQ6W85Z3tAm6PJUPFWAPrUYz",
                        "7BQuDrX1X6VIVVtitRhfLCEWyEpmVMt0jb7IaQg2T"
                )
        ));

        List<String> phoneNumbers = new ArrayList<>();
        phoneNumbers.add(phoneNumber);
        String templateId = "UTA211227LOVSE4";

        SendUSMSMessageParam param = new SendUSMSMessageParam(phoneNumbers, templateId);
        param.setSigContent("SIG20211214D4049E");
        param.setProjectId("org-by3nce");

        List<String> templateParams = new ArrayList<>();
        templateParams.add(code);
        param.setTemplateParams(templateParams);
        SendUSMSMessageResult result = null;
        try {
            result = client.sendUSMSMessage(param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(result);
        System.out.println(code);
        return  result.toString();
    }

}
